package cn.jeefast.modules.platform.controller;


import cn.jeefast.common.entity.MbResearchStep;
import cn.jeefast.common.entity.MbResearchStepDataTemplateAnotherIndicators;
import cn.jeefast.common.entity.MbResearchStrpDataTemplate;
import cn.jeefast.common.utils.R;
import cn.jeefast.modules.platform.service.MbResearchStepDataTemplateAnotherIndicators1Service;
import cn.jeefast.modules.platform.service.MbResearchStepDataTemplateMainIndicators1Service;
import cn.jeefast.modules.platform.service.MbResearchStepDataTemplateObjectiveIndicators1Service;
import cn.jeefast.modules.platform.service.MbResearchStrpDataTemplate1Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.jeefast.common.base.BaseController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author theodo
 * @since 2020-01-06
 */
@RestController
@RequestMapping("/mbResearchStrpDataTemplate")
@CrossOrigin
public class MbResearchStrpDataTemplate1Controller extends BaseController {
    @Autowired
	private MbResearchStrpDataTemplate1Service researchStrpDataTemplateService;
    @Autowired
    private MbResearchStepDataTemplateAnotherIndicators1Service mbResearchStepDataTemplateAnotherIndicators1Service;
    @Autowired
    private MbResearchStepDataTemplateMainIndicators1Service mbResearchStepDataTemplateMainIndicators1Service;
    @Autowired
    private MbResearchStepDataTemplateObjectiveIndicators1Service mbResearchStepDataTemplateObjectiveIndicators1Service;
    @Autowired
    private MbResearchStrpDataTemplate1Service mbResearchStrpDataTemplate1Service;

    /**
     * 模板列表
     * @param resId
     * @return
     */
    @RequestMapping("/list")
    public R list(Long resId){
        EntityWrapper ew = new EntityWrapper();
        ew.eq("res_id",resId);
        List list = researchStrpDataTemplateService.selectList(ew);
        return R.ok().put("data",list);
    }

    /**
     * 模板详情
     * @param tempId
     * @return
     */
    @RequestMapping("detail")
    public R detail(Long tempId){
        MbResearchStrpDataTemplate mbResearchStrpDataTemplate = mbResearchStrpDataTemplate1Service.selectById(tempId);
        Map map = new HashMap();
        EntityWrapper ew1 = new EntityWrapper();
        ew1.eq("temp_id",tempId);
        List list1 = mbResearchStepDataTemplateAnotherIndicators1Service.selectList(ew1);
        map.put("ai",list1);
        EntityWrapper ew2 = new EntityWrapper();
        ew2.eq("temp_id",tempId);
        List list2 = mbResearchStepDataTemplateMainIndicators1Service.selectList(ew2);
        map.put("mi",list2);
        EntityWrapper ew3 = new EntityWrapper();
        ew3.eq("temp_id",tempId);
        List list3 = mbResearchStepDataTemplateObjectiveIndicators1Service.selectList(ew3);
        map.put("oi",list3);
        return R.ok().put("data",map).put("template",mbResearchStrpDataTemplate);
    }

    public R aiAddOrSave(MbResearchStepDataTemplateAnotherIndicators ai){
        if(ai.getAiId()==null){
            mbResearchStepDataTemplateAnotherIndicators1Service.insert(ai);
        }else{
            mbResearchStepDataTemplateAnotherIndicators1Service.updateById(ai);
        }
        return R.ok();
    }

    /**
     * 添加或编辑模板
     * @param researchStrpDataTemplate
     * @return
     */
    @RequestMapping("/addOrSave")
    public R addOrSave(MbResearchStrpDataTemplate researchStrpDataTemplate){
        if(researchStrpDataTemplate.getTempId()==null){
            researchStrpDataTemplateService.insert(researchStrpDataTemplate);
            return R.ok().put("id",researchStrpDataTemplate.getTempId());
        }else{
            researchStrpDataTemplateService.updateById(researchStrpDataTemplate);
        }
        return R.ok();
    }
}
